﻿using CarAppDomain.CarType.IService;
using CarAppDto.CarType.CountryDtos;
using D.UtilCore;
using D.UtilCore.Dtos;
using D.UtilCore.Filters;
using D.UtilSqlsugarOrm;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;

namespace CarAppAPI.CarType
{
    /// <summary>
    /// 国家模块
    /// </summary>
    [Route("/api/[controller]/[action]")]
    [Authorize]
    public class CountryController : BaseApiController
    {

        private readonly ICountryService _CountryService;
        public CountryController(ICountryService CountryService)
        {
            _CountryService = CountryService;
        }

        /// <summary>
        /// 新增
        /// </summary>
        /// <param name="reqAddAdmin"></param>
        /// <returns></returns>
        [HttpPost, TypeFilter(typeof(ExtActionFilterAttribute))]
        [Authorize]
        public async Task<ApiResult<int>> Add([FromBody] ReqAddCountry reqModel)
        {
            reqModel.CreateUser = Account;
            return await _CountryService.AddCountryAsync(reqModel);
        }

        /// <summary>
        /// 删除
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        [HttpDelete("{ids}"), TypeFilter(typeof(ExtActionFilterAttribute))]
        [Authorize]
        public async Task<ApiResult<int>> Delete(string ids)
        {
            var idsArray = ids.Split(",");
            return await _CountryService.DeleteCountryAsync(idsArray.ToList());
        }

        /// <summary>
        /// 修改
        /// </summary>
        /// <param name="id"></param>
        /// <param name="reqUpdateAdmin"></param>
        /// <returns></returns>
        [HttpPut, TypeFilter(typeof(ExtActionFilterAttribute))]
        [Authorize]
        public async Task<ApiResult<int>> Update([FromBody] ReqUpdateCountry reqModel)
        {
            reqModel.UpdateUser = Account;
            return await _CountryService.UpdateCountryAsync(reqModel);
        }

        /// <summary>
        /// 获取详情
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        [HttpGet("{id}"), TypeFilter(typeof(ExtActionFilterAttribute))]
        [Authorize]
        public async Task<ApiResult<RepCountry>> Get(string? id)
        {
            return await _CountryService.GetCountryAsync(id);
        }

        /// <summary>
        /// 获取列表
        /// </summary>
        /// <param name="reqGueryAdminList"></param>
        /// <returns></returns>
        [HttpPost, TypeFilter(typeof(ExtActionFilterAttribute))]
        [Authorize]
        public async Task<ApiResult<List<RepCountry>>> List([FromBody] ReqQueryCountryList reqCountry)
        {
            return await _CountryService.QueryCountryListAsync(reqCountry);
        }

        /// <summary>
        /// 分页
        /// </summary>
        /// <returns></returns>
        [HttpPost, TypeFilter(typeof(ExtActionFilterAttribute))]
        [Authorize]
        public async Task<ApiResult<PageModel<RepCountry>>> Pages([FromBody] ReqQueryCountryPage reqQueryPage)
        {
            return await _CountryService.QueryCountryPagesAsync(reqQueryPage);
        }
    }
}
